#ifndef APP_STATE_HPP
#define APP_STATE_HPP

#include "../define.hpp"

class AppState
{
public:
	AppState(const std::string nameID, App* appPtr) : m_nameID(nameID),
		m_app(appPtr),
		m_paused(false),
	    m_init(false),
		m_cleanUp(false)
	{
	}

	virtual ~AppState()
	{
		m_app = NULL;
	}


	const std::string NameID() { return m_nameID; }

	virtual void DoInit()
	{
		if(m_init == false)
		{
			m_init = true;
			m_paused = false;
            // We start the active clock
            m_activeClock.Reset();

		}
	}


	virtual void ReInit() =  0;

	virtual void DeInit()
	{
		if(m_init == true)
		{
			m_cleanUp = true;
			m_init = false;
		}
	}

	bool IsPaused() { return m_paused; }

	virtual void Pause()
	{
		if(m_paused == false)
		{
			m_paused = true;
            m_activeTime += m_activeClock.GetElapsedTime();

            m_pausedClock.Reset();
		}
	}

	virtual void Resume()
	{
		if(m_paused == true)
		{
			m_paused = false;
            m_pausedTime += m_pausedClock.GetElapsedTime();

            m_activeClock.Reset();
		}
	}

	virtual void HandleEvents(sf::Event appEvent) = 0;
	virtual void Update(float elapsedTime) { }
	virtual void Draw() = 0;
	void HandleCleanUp()
	{
		if(m_cleanUp == true)
		{
			CleanUp();

			m_cleanUp = false;
		}
	}

    float TotalTimeActive()
    {
        if(m_paused == false)
        {
            float total;
            total += m_activeTime;
            total += m_activeClock.GetElapsedTime();

            return total;
        }

        return m_activeTime;
    }

    float TotalTimePaused()
    {
        if(m_paused == true)
        {
            float total;
            total += m_pausedTime;
            total += m_pausedClock.GetElapsedTime();

            return total;
        }

        return m_pausedTime;
    }


	virtual void CleanUp() = 0;

protected:
	App* m_app;
private:
	const std::string m_nameID;

	bool m_paused;

	bool m_cleanUp;

	bool m_init;

    sf::Clock m_activeClock;

    float m_activeTime;

	sf::Clock m_pausedClock;

	float m_pausedTime;

	

    //AppState(const &AppState);  // undefined

    //AppState& operator=(const &AppState); //  undefined



};

#endif
